package top.malaoshi.service;


import org.springframework.stereotype.Service;
import top.malaoshi.entity.UserModel;
import top.malaoshi.mapper.IUserMapper;
import top.malaoshi.model.Result;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class RegSrvImpl {

    @Resource
    private IUserMapper dao;

    public Result reg(String password, String phone){
        System.out.println("RegSrvImpl"+password+phone);

        List<UserModel> list=dao.queryByPhone(phone);
        Result res=new Result();
        if(list.size()==0){
            Date date=new Date();
            UserModel um=new UserModel();
            String uuid= UUID.randomUUID().toString().replace("-","");
            um.setId(uuid);
            um.setPhone(phone);
            um.setPassword(password);
            um.setName("");
            um.setRole("100");
            um.setStatus("1");
            um.setCreateTime(date);
            um.setUpdateTime(date);
            dao.insert(um);
            //0表示可以增加
            res.setCode(0);
            //res.setMsg("可以增加");
        }else{
            //101表示重复了注册增加
            res.setCode(101);
            res.setMsg("增加失败");
        }
        return res;

    }
}
